package com.flower.algorithm.queue;

/**
 * @ClassName Queues
 * @Description TODO
 * @Author 数组模拟队列实现
 * @Date 2021/10/27 11:19
 * @Version 1.0
 */
public class Queues {
    int maxSize;
    int rear;
    int front;
    int[] array;
    // 初始化队列
    public Queues(int maxSize){
        this.rear=-1;// 指向队头前一个位置
        this.front = -1;// 指向队尾后一个位置
        this.maxSize = maxSize;
        this.array = new int[maxSize];
    }
    // 判断是否队空
    public boolean isEmpty(){
        return this.rear==this.front;
    }
    // 判断是否队满
    public boolean isFull() {
        return this.rear==this.maxSize-1;
    }
    // 入队列
    public void addQueue(int num){
        if(isFull()){
            throw new RuntimeException("队列已满");
        }
        this.rear++;
        this.array[this.rear]=num;
    }
    public int poll() {
        if(isEmpty()){
            throw new RuntimeException("队列为空");
        }
        this.front++;
        return this.array[this.front];
    }
}
